import request from "@/utils/request";

// 文件导入（仅上传单个文件）
export function machineLedgerEntryFileImport(file, porjectId, ledgerTypeId) {
  const formData = new FormData();
  const raw = file && file.raw ? file.raw : file;
  if (raw) {
    // 后端现在只需要一个文件
    formData.append("file", raw);
  }
  // 添加项目ID和台账类型ID参数
  if (porjectId) {
    formData.append("porjectId", porjectId);
  }
  if (ledgerTypeId) {
    formData.append("ledgerTypeId", ledgerTypeId);
  }
  return request({
    url: "/cost/machineLedgerEntry/importData",
    method: "post",
    data: formData,
    headers: {
      "X-Requested-With": "XMLHttpRequest",
    },
  });
}

// 查询机械台账填报列表
export function listMachineLedgerEntry(query) {
  return request({
    url: "/cost/machineLedgerEntry/list",
    method: "get",
    params: query,
  });
}

// 查询机械台账填报所有列表
export function listAllMachineLedgerEntry(query) {
  return request({
    url: "/cost/machineLedgerEntry/listAll",
    method: "get",
    params: query,
  });
}

// 查询机械台账填报详细
export function getMachineLedgerEntry(id) {
  return request({
    url: "/cost/machineLedgerEntry/getInfo/" + id,
    method: "get",
  });
}

// 新增机械台账填报
export function addMachineLedgerEntry(data) {
  return request({
    url: "/cost/machineLedgerEntry/add",
    method: "post",
    data: data,
  });
}

// 修改机械台账填报
export function updateMachineLedgerEntry(data) {
  return request({
    url: "/cost/machineLedgerEntry/edit",
    method: "post",
    data: data,
  });
}

// 删除机械台账填报
export function delMachineLedgerEntry(id) {
  return request({
    url: "/cost/machineLedgerEntry/remove/" + id,
    method: "get",
  });
}

// 获取项目总含税金额
export function getAmountTotal(ledgerTypeId, projectId) {
  return request({
    url: "/cost/machineLedgerEntry/getAmountTotal",
    method: "get",
    params: {
      ledgerTypeId,
      projectId,
    },
  });
}
